import { createRouter, createWebHistory } from 'vue-router'
import HomeView from '../views/HomeView.vue'
import Search from '@/views/Search.vue'
import Login from '@/views/Login.vue'
import InfoUser from '@/views/InfoUser.vue'
import AllVideoList from '@/views/AllVideoList.vue'
import ceshi from '@/views/ceshi.vue'

import store from '@/store/index'

const routes = [
  {
    path: '/',
    name: 'home',
    component: HomeView
  },
  {
    path: '/about',
    name: 'about',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  }, {
    path: '/ceshi',
    name: '测试题',
    component:ceshi
  },
  {
    path: '/itemMusic',
    name: 'about',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import('@/views/ItemMusic.vue')
  },{
    path: '/search',
    name: 'search',
    component:Search
  },{
    path: '/login',
    name: 'login',
    component:Login
  },{
    path: '/infoUser',
    name: 'infoUser',
    component: InfoUser,
    beforeEnter(to, from, next) {
      if (store.state.isLogin) {
        next()
      } else {
        next('/login')
      }
    },
  },{
    path: '/allvideolist',
    name: 'allvideolist',
    component:AllVideoList
  },
]

const router = createRouter({
  history: createWebHistory(process.env.BASE_URL),
  routes
})

router.beforeEach((to, from) => {
  if (to.path == '/login') {
    store.state.isFooterMusicShow = false
  } else {
    store.state.isFooterMusicShow = true
  }
});

export default router
